package com.xigua._树;

import com.xigua.TreeNode;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 请完成一个函数，输入一个二叉树，该函数输出它的镜像。
 * @date 2022/3/1623:00
 */
public class _剑指_Offer27_二叉树的镜像 {


    public static void main(String[] args) {
        TreeNode root = new TreeNode(4);
        TreeNode left = new TreeNode(2,new TreeNode(1),new TreeNode(3));
        TreeNode right = new TreeNode(7,new TreeNode(6),new TreeNode(9));
        root.right = right;
        root.left = left;
        TreeNode node = mirrorTree(root);
        System.out.println(node);
    }

    public static TreeNode mirrorTree(TreeNode root) {
        if (root == null ) return root;
        TreeNode left = mirrorTree(root.left);
        TreeNode right = mirrorTree(root.right);
        root.right = left;
        root.left = right;
        return root;
    }



}
